if (!jsx3.lang.Class.forName("ux.cdb.admin.queries.organ.DetailDialog")) {

jsx3.Class.defineClass(
	"ux.cdb.admin.queries.organ.DetailDialog", jsx3.gui.Dialog, [],
	function (objRoot) {
		/* objRoot.prototype.initialize = function(){
			var dialog = this;
			ux.megatron.Main.loadUIResourceAsync(dialog.getDescendantOfName('tab1').getContentPane(), "ux.cdb.admin", "ux/cdb/admin/mechanism/cooOrg/CooOrgLoanAssist/ui/CooOrgLoanAssistSummary.xml", this, function(){});
			ux.megatron.Main.loadUIResourceAsync(dialog.getDescendantOfName('tab2').getContentPane(), "ux.cdb.admin", "ux/cdb/admin/mechanism/cooOrg/CooOrgLoanAssist/ui/CooOrgLoanAssistAddress.xml", this, function(){});
			ux.megatron.Main.loadUIResourceAsync(dialog.getDescendantOfName('tab3').getContentPane(), "ux.cdb.admin", "ux/cdb/admin/mechanism/cooOrg/CooOrgLoanAssist/ui/CooOrgLoanAssistLinkman.xml", this, function(){});
			ux.megatron.Main.loadUIResourceAsync(dialog.getDescendantOfName('tab4').getContentPane(), "ux.cdb.admin", "ux/cdb/admin/mechanism/cooOrg/CooOrgLoanAssist/ui/CooOrgLoanAssistBaseinfo.xml", this, function(){});
		} */
        objRoot.prototype.loadCount = 0;
		
        objRoot.prototype.initialize = function() {
			var me = this;
			this.parent = ux.megatron.Main.getServer().getBodyBlock().get('blkOrganWorld');
			this.matrix = this.parent.matrix;
			jsx3.log('aggreement#DetailDialog loaded. parent : ' + this.parent);
			jsx3.log('aggreement#DetailDialog loaded. matrix : ' + this.matrix);
			
			this.ruleSelected();
		}		
		
        objRoot.prototype.ruleSelected = function(){//user selected some record
            var detailPanel = this.getDescendantOfName("tabbedpane");
			console.log("\r\r\t cooorg selected record is "+this.matrix.getSelectedNodes());
            var orgType = this.matrix.getSelectedNodes().get(0).getAttribute("cooperOrgTypeCode");
			console.log("\r\r\t cooorg selected orgType is "+orgType);
			if (this.lastType==orgType)
			{//type not changed,do not need load panel again,load data diectly
				if (orgType == "2401") {
					this.loadCount=3;
					this.loanAssistTypeLoaded();
					return;
				}
				
			}
			if (orgType == "2401") {
				this.showPaneTypeLoanAssist();
				//display the tab
	            detailPanel.setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
			
			}
			else{
				//show the notice panel hiiden the detail panel
	            detailPanel.setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
			}
			this.lastType=orgType;
     
        }
        objRoot.prototype.ruleChecked = function(mtx){//user checked some record
            if (this.matrix.getCheckedNodes().size() > 0) {
                this.btnDelete.setEnabled(jsx3.gui.Form.STATEENABLED, true);
                if (this.matrix.getCheckedNodes().size() == 1) {
                    this.btnEdit.setEnabled(jsx3.gui.Form.STATEENABLED, true);
                }
                else {
                    this.btnEdit.setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                }
            }
            else {
                this.btnDelete.setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                this.btnEdit.setEnabled(jsx3.gui.Form.STATEDISABLED, true);
            }
        }
        //invest type
        objRoot.prototype.showPaneTypeInvest = function(){
            var me = this;
            var tabname = [{
                name: "tab_cooOrg_Baseinfo",
                url: "ux/cdb/admin/mechanism/cooOrg/CooOrgInvest/ui/CooOrg_Detail_Baseinfo.xml"
            }, {
                name: "tab_cooOrg_Address",
                url: "ux/cdb/admin/mechanism/cooOrg/CooOrgInvest/ui/CooOrg_Detail_Address.xml"
            }, {
                name: "tab_cooOrg_Linkman",
                url: "ux/cdb/admin/mechanism/cooOrg/CooOrgInvest/ui/CooOrg_Detail_Linkman.xml"
            }, {
                name: "tab_cooOrg_StockHolder",
                url: "ux/cdb/admin/mechanism/cooOrg/CooOrgInvest/ui/CooOrg_Detail_StockHolder.xml"
            }, {
                name: "tab_cooOrg_Manager",
                url: "ux/cdb/admin/mechanism/cooOrg/CooOrgInvest/ui/CooOrg_Detail_Manager.xml"
            }, {
                name: "tab_cooOrg_Credit",
                url: "ux/cdb/admin/mechanism/cooOrg/CooOrgInvest/ui/CooOrg_Detail_Credit.xml"
            }];
            this.showTabs(tabname,null);
            
            
        }
		//loan assist type
        objRoot.prototype.showPaneTypeLoanAssist = function(){
            var me = this;
            var tabname = [{
                name: "tab_cooOrg_Baseinfo",
                url: "ux/cdb/admin/mechanism/cooOrg/CooOrgLoanAssist/ui/CooOrgLoanAssistSummary.xml"
            }, {
                name: "tab_cooOrg_Address",
                url: "ux/cdb/admin/mechanism/cooOrg/CooOrgLoanAssist/ui/CooOrgLoanAssistAddress.xml"
            }, {
                name: "tab_cooOrg_Linkman",
                url: "ux/cdb/admin/mechanism/cooOrg/CooOrgLoanAssist/ui/CooOrgLoanAssistLinkman.xml"
            }, {
                name: "tab_cooOrg_StockHolder",
				title: "@cdb@Mechanism@CooOrg@LoanAssist@BaseinfoTitle",
                url: "ux/cdb/admin/mechanism/cooOrg/CooOrgLoanAssist/ui/CooOrgLoanAssistBaseinfo.xml"
            }, {
                name: "tab_cooOrg_Manager",
                url: "none"
            }, {
                name: "tab_cooOrg_Credit",
                url: "none"
            }];
            this.showTabs(tabname,this.loanAssistTypeLoaded);
            
            
        }
        //assure type
        objRoot.prototype.showPaneTypeAssure = function(){
            var me = this;
            var tabname = [{
                name: "tab_cooOrg_Baseinfo",
                url: "ux/cdb/admin/mechanism/cooOrg/CooOrgAssure/ui/CooOrg_Assure_Baseinfo.xml"
            }, {
                name: "tab_cooOrg_Address",
                url: "ux/cdb/admin/mechanism/cooOrg/CooOrgInvest/ui/CooOrg_Detail_Address.xml"
            }, {
                name: "tab_cooOrg_Linkman",
                url: "ux/cdb/admin/mechanism/cooOrg/CooOrgInvest/ui/CooOrg_Detail_Linkman.xml"
            }, {
                name: "tab_cooOrg_StockHolder",
                url: "ux/cdb/admin/mechanism/cooOrg/CooOrgInvest/ui/CooOrg_Detail_StockHolder.xml"
            }, {
                name: "tab_cooOrg_Manager",
                url: "ux/cdb/admin/mechanism/cooOrg/CooOrgInvest/ui/CooOrg_Detail_Manager.xml"
            }, {
                name: "tab_cooOrg_Credit",
                url: "ux/cdb/admin/mechanism/cooOrg/CooOrgInvest/ui/CooOrg_Detail_Credit.xml"
            }];
            this.showTabs(tabname,null);
            
            
        }
        //credit type
        objRoot.prototype.showPaneTypeCredit = function(){
            var me = this;
            var tabname = [{
                name: "tab_cooOrg_Baseinfo",
                url: "ux/cdb/admin/mechanism/cooOrg/CooOrgCredit/ui/CooOrg_Credit_Baseinfo.xml"
            }, {
                name: "tab_cooOrg_Address",
                url: "ux/cdb/admin/mechanism/cooOrg/CooOrgInvest/ui/CooOrg_Detail_Address.xml"
            }, {
                name: "tab_cooOrg_Linkman",
                url: "ux/cdb/admin/mechanism/cooOrg/CooOrgInvest/ui/CooOrg_Detail_Linkman.xml"
            }, {
                name: "tab_cooOrg_StockHolder",
                url: "none"
            }, {
                name: "tab_cooOrg_Manager",
                url: "none"
            }, {
                name: "tab_cooOrg_Credit",
                url: "none"
            }];
            this.showTabs(tabname,null);
            
            
        }
        //cooperation type
        objRoot.prototype.showPaneTypeCoop = function(){
            var me = this;
            var tabname = [{
                name: "tab_cooOrg_Baseinfo",
                url: "ux/cdb/admin/mechanism/cooOrg/CooOrgCoop/ui/CooOrg_Coop_Baseinfo.xml"
            }, {
                name: "tab_cooOrg_Address",
                url: "ux/cdb/admin/mechanism/cooOrg/CooOrgInvest/ui/CooOrg_Detail_Address.xml"
            }, {
                name: "tab_cooOrg_Linkman",
                url: "ux/cdb/admin/mechanism/cooOrg/CooOrgInvest/ui/CooOrg_Detail_Linkman.xml"
            }, {
                name: "tab_cooOrg_StockHolder",
                url: "none"
            }, {
                name: "tab_cooOrg_Manager",
                url: "none"
            }, {
                name: "tab_cooOrg_Credit",
                url: "none"
            }];
            this.showTabs(tabname,null);
            
            
        }
        objRoot.prototype.showTabs = function(tabs,callbackFunc){
			var server=ux.megatron.Main.getServer();
			var me=this;

            for (var i = 0; i < tabs.length; i++) {
                var tabBaseinfo = this.getDescendantOfName(tabs[i].name);
                tabBaseinfo.getContentPane().removeChildren();
                if (tabs[i].url != "none") {
					if (tabs[i].title)
					{
						tabBaseinfo.setText(server.getDynamicProperty(tabs[i].title), true);
					}
					else
					{
						tabBaseinfo.setText(server.getDynamicProperty("@cdb@Mechanism@CooOrg@tabCooRegDetailStockholder"), true);
					}
		
					ux.megatron.Main.loadUIResourceAsync(tabBaseinfo.getContentPane(), "ux.cdb.admin", tabs[i].url,me,callbackFunc);
		
					tabBaseinfo.setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
				}
                else {
                    tabBaseinfo.setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                }
            }
        }
		/**
		 * callback function of loan assit detail panel
		 */
		objRoot.prototype.loanAssistTypeLoaded=function()
		{
			this.loadCount+=1;
			console.log("\r\r [CooOrg.js][267]: loadCount+1 now:"+this.loadCount);
			if (this.loadCount == 4) {
				this.loadCount=0;
				//the detail panel of the load assist loaded, call the server operation to get the data
				var me = this;
				var details = new Array();
				var record = this.matrix.getSelectedNodes().get(0);
				details.push(this.getDescendantOfName("tab_cooOrg_Baseinfo").getContentPane().getDescendantOfName("blkLoanAssistSummaryDetail"));//summary info
				details.push(this.getDescendantOfName("tab_cooOrg_Address").getContentPane().getDescendantOfName("blkLoanAssistAddressShowDetail"));
				details.push(this.getDescendantOfName("tab_cooOrg_StockHolder").getContentPane().getDescendantOfName("blkLoanAssistBaseinfoShowDetail"));
				
				for (var i = 0; i < details.length; i++) {
					details[i].setDataEntityType(ux.cdb.admin.dataautomate.GenericDetail.CooperOrg);
					details[i].setDataEntityId(record.getAttribute("partyId"));//id=CooOrgID
					if (i == 0) {
						//first get data,dispose the special date for linkman address and regioncode
						details[i].setProcessHandler(function(obj){
							return me.showLoanAssistLinkman(obj);
						});
						
					}
					details[i].refreshData();
				}
			}
			else
			{
				return;
			}
		}
		/**
		 * the function to assemble the likeman cache
		 */
		objRoot.prototype.showLoanAssistLinkman=function(data)
		{
			console.log("\r\r\t"+ux.megatron.util.JSON.JSONtoString(data)+"\r");

			//assemble the linkman info
			var cache=jsx3.xml.CDF.Document.newDocument();
			var record;
			var records=data.contactPersonList;
			/*if (records.length)
			{*/
			//mulit-record
			for(var i=0;i<records.length;i++)
			{
				record={
						jsxid:records[i].contactPersonId,
						jsxtype:records[i].contactPersonTypeCode,
						jsxname:records[i].contactPersonName,
						jsxtelephone:records[i].contactPersonFixPhone,
						jsxcellphone:records[i].contactPersonMobNum,
						jsxemail:records[i].contactPersonEmail
						};
	
				cache.insertRecord(record);			
			}
            ux.megatron.Main.getServer().getCache().setDocument("cchLoanAssistLinkmanShowDetail",cache);
			this.getDescendantOfName("tab_cooOrg_Linkman").getContentPane().getDescendantOfName("mtx_CooOrg_Linkman").repaintData();
			
			return data;
		}
		
		/*
		 *   call service operation to get list
		 */
		objRoot.prototype.callGetCooperOrgUCC=function()
		{
			ux.megatron.util.Dwr.callDwr("GetCooperOrgUCC", "getCooperOrgListByCondition", [null,null,null,null,1,this.pageSize], this, this.loadCooOrgList);
		}
		
        //load cooperation orgnization list
        objRoot.prototype.loadCooOrgList = function(objEvent){
			 this.lastType=null;
			 //show the notice panel hiiden the detail panel
			 var detailPanel = this.getDescendantOfName("tabbedpane");
             detailPanel.setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
        	//got the data  assemble the cache 
			var cache=jsx3.xml.CDF.Document.newDocument();
			var record;
			this.totalCount=objEvent.content.page.count;
			var recordinfo=objEvent.content.data;
			
			this.totalPage=Math.ceil(this.totalCount/this.pageSize);
			
			this.getDescendantOfName("txtPageNoInput").setValue(this.currPage);//show currpage

			if (recordinfo != null) {
				if (recordinfo.length) {//mulit-record
					for (var i = 0; i < recordinfo.length; i++) {
						record = {
							jsxid: i,
							jsxcode: recordinfo[i].partyId,									
							jsxname: recordinfo[i].chnFullName,
							jsxBranch: recordinfo[i].internalOrgName,
							jsxType: recordinfo[i].cooperOrgTypeCode,
							jsxTypeName:recordinfo[i].cooperOrgTypeName,
							jsxRegion: recordinfo[i].logicalAreaName
						};
						
						cache.insertRecord(record);
					}
				}
			}
			
            ux.megatron.Main.getServer().getCache().setDocument("cchCooOrgList",cache);
			
			this.matrix.repaint();
			this.ruleChecked();
        }
	});

}